package cliente;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author triki
 */

import aso.upna.config.ClientConfig;
import aso.upna.exceptions.MediaPlayerNotReady;
import aso.upna.exceptions.NoFileLoaded;
import aso.upna.filesystem.SharedFolder;
import aso.upna.threads.ClientConnect;
import aso.upna.threads.UdpStream;
import aso.upna.threads.ServerListenerThread;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Timer;


public class AudioPlayer {
    private static final int BYTES = 100;
    private static final int BUFFER_SIZE =10000;
   
    public static void main(String[] args) throws MediaPlayerNotReady, IOException, InterruptedException {

        byte[] aux = new byte[10];
        InputStream is = null;

        String a = "javier";
        String b = "";

        System.out.println("comp: "+a.compareToIgnoreCase(b));

        //SharedFolder sf = new SharedFolder("/media/datos/personal/mp3/",".mp3");
        //SharedFolder sf = new SharedFolder("./",".mp3");
        /*sf.listFiles();
        ClientConfig cfg = new ClientConfig("./",9999,9999);
        cfg.createServerSocket();
        cfg.createUdpSocket();

        Thread.sleep(2000);

        ServerListenerThread server = new ServerListenerThread(cfg);
        Thread hiloServer = new Thread(server);
        hiloServer.start();

        ClientConnect cc = new ClientConnect(cfg,"127.0.0.1",9999,"I_Can.mp3");
        Thread connect = new Thread(cc);
        connect.start();
        /*UdpStream client = new UdpStream(cfg);
        Thread hiloClient = new Thread(client);
        hiloClient.start();

        Reproductor rp = new Reproductor(cfg.getPathToTempFile());*/

        //rp.play();
       /*try
        {
            //Socket sock = new Socket("127.0.0.1", 9999);
            //is = sock.getInputStream();
           // File f = new File("./I_Can(prueba).mp3");
           // FileOutputStream os = new FileOutputStream(f);
            //int i=0;
            
            Hilo runnable = new Hilo(345,"./I_Can(prueba).mp3");
            Thread thread = new Thread(runnable);

            //Una vez instanciado la clase es necesario inicializar el reproductor
            //Esto podra a punto todos los elementos del sistema.
            runnable.startUpAudioPlayer();

            System.out.println("Buffering...");

            int delay = 1000; //milliseconds
            ActionListener taskPerformer = new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                      //Accion a ejecutar cuando salte la alarma.
                  }
              };
              
            new Timer(delay, taskPerformer).start();

            while (is.read(aux) != -1)
            {
                os.write(aux);
                i++;
                
                if(i == 10000)
                {
                    thread.start();
                }

                //runnable.getCurrentDuration();
                //runnable.getCurrentPosition();

            }
            System.out.println("Transferencia de fichero Terminada.");
            System.in.read();
            runnable.getCurrentDuration();
            runnable.getCurrentPosition();
            System.in.read();
            runnable.stop();

        } catch (IOException ex) {
           ex.printStackTrace();
        }*/
    }
}
